package c.x.jy.wexin.controller;

import c.x.jy.common.annotation.Login;
import c.x.jy.common.utils.PageUtils;
import c.x.jy.common.utils.R;
import c.x.jy.dao.entity.MemberEntity;
import c.x.jy.service.service.MemberService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * 会员信息表
 *
 * @author amwhyh
 * @email xxx@xx.com
 * @date 2021-05-20 20:09:48
 */
@RestController
@RequestMapping("wechat/member")
public class MemberController {
	@Autowired
	private MemberService memberService;

	/**
	 * 列表
	 */
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params) {

		PageUtils page = memberService.queryPage(params);

		return R.put(page);
	}

	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	public R info(@PathVariable("id") Long id) {
		MemberEntity member = memberService.getById(id);

		return R.put(member);
	}

	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("member:member:save")
	public R save(@RequestBody MemberEntity member) {
		memberService.save(member);

		return R.ok();
	}

 
    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody MemberEntity member){
		memberService.updateById(member);
        memberService.removeMemberCache(member);
        return R.ok();
    }
 

	/**
	 * 删除
	 */
	@RequestMapping("/delete/{id}")
	@RequiresPermissions("member:member:delete")
	public R delete(@PathVariable("id") Long id) {
		memberService.removeByIds(Arrays.asList(id));

		return R.ok();
	}

	/**
	 * 我的下线 （人脉）
	 */
	@Login
	@RequestMapping("/myconnection")
	public R myconnection( ) {
		return R.put(memberService.countmymyconnection(memberService.getCurrUser().getId()));
	}
	/**
	 * 我的下线 （人脉）
	 */
	@Login
	@RequestMapping("/countmymyconnectionlist")
	public R countmymyconnectionlist( ) {
		return R.put(memberService.countmymyconnectionlist(memberService.getCurrUser().getId()));
	}

}
